/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */

package com.ykht.proj.coupon.controller.c;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ykht.proj.common.core.util.R;
import com.ykht.proj.common.log.annotation.SysLog;
import com.ykht.proj.coupon.entity.CnLabel;
import com.ykht.proj.coupon.service.CnLabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 标签表
 *
 * @author proj code generator
 * @date 2020-11-16 17:00:21
 */
@RestController
@AllArgsConstructor
@RequestMapping("c/cnlabel")
@Api(value = "cnlabel", tags = "c端标签相关")
public class LabelController {

	private final CnLabelService cnLabelService;

	/**
	 * 分页查询
	 *
	 * @param page    分页对象
	 * @param cnLabel 标签表
	 * @return
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/page")
	public R getCnLabelPage(Page page, CnLabel cnLabel) {
		return R.ok(cnLabelService.page(page, Wrappers.query(cnLabel)));
	}


	/**
	 * 通过id查询标签表
	 *
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}")
	public R getById(@PathVariable("id") Long id) {
		return R.ok(cnLabelService.getById(id));
	}

	/**
	 * 新增标签表
	 *
	 * @param cnLabel 标签表
	 * @return R
	 */
	@ApiOperation(value = "新增标签表", notes = "新增标签表")
	@SysLog("新增标签表")
	@PostMapping
	public R save(@RequestBody CnLabel cnLabel) {
		return R.ok(cnLabelService.save(cnLabel));
	}

	/**
	 * 修改标签表
	 *
	 * @param cnLabel 标签表
	 * @return R
	 */
	@ApiOperation(value = "修改标签表", notes = "修改标签表")
	@SysLog("修改标签表")
	@PutMapping
	public R updateById(@RequestBody CnLabel cnLabel) {
		return R.ok(cnLabelService.updateById(cnLabel));
	}

	/**
	 * 通过id删除标签表
	 *
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id删除标签表", notes = "通过id删除标签表")
	@SysLog("通过id删除标签表")
	@DeleteMapping("/{id}")
	public R removeById(@PathVariable Long id) {
		return R.ok(cnLabelService.removeById(id));
	}

}
